package graph.group.zhangtao.guider.homepage.activities;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

;import graph.group.zhangtao.guider.R;

/**
 * Created by T5 on 2016/6/16.
 */
public class ToolBarX {
    private Toolbar mToolbar;
    private AppCompatActivity mActivity;
    private ActionBar mActionBar;
    private RelativeLayout rlCustom;

    public ToolBarX(Toolbar mToolbar, final AppCompatActivity mActivity){
        this.mActivity = mActivity;
        this.mToolbar = mToolbar;
        rlCustom = (RelativeLayout) mToolbar.findViewById(R.id.rlContent);
        mActivity.setSupportActionBar(mToolbar);
        mActionBar = mActivity.getSupportActionBar();
        mActionBar.setDisplayHomeAsUpEnabled(true);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivity.finish();
            }
        });

    }

    public ToolBarX setTitle(String title){
        TextView toolbarTitle = (TextView) mActivity.findViewById(R.id.toolbar_title);
        mActionBar.setTitle("");
        toolbarTitle.setText(title);
        //mActionBar.setTitle(title);
        return this;
    }

    public ToolBarX setSubTitle(String subTitle){
        mActionBar.setSubtitle(subTitle);
        return this;
    }

    public ToolBarX setTitle(int resId){
        mActionBar.setTitle(resId);
        return this;
    }

    public ToolBarX setSubTitle(int resId){
        mActionBar.setSubtitle(resId);
        return this;
    }

    public ToolBarX setNavigationOnClickListener(View.OnClickListener listener){
        mToolbar.setNavigationOnClickListener(listener);
        return this;
    }

    public ToolBarX setNavigationIcon(int resId){
        mToolbar.setNavigationIcon(resId);
        return this;
    }

    public ToolBarX setDisplayHomeAsUpEnabled(boolean show){
        mActionBar.setDisplayHomeAsUpEnabled(show);
        return this;
    }

    public ToolBarX setCustomView(View view){
        rlCustom.removeAllViews();
        rlCustom.addView(view);
        return this;
    }

    public ToolBarX setVisibility(int i){
        if (i== View.GONE){
            mToolbar.setVisibility(View.GONE);
        }else if (i== View.VISIBLE){
            mToolbar.setVisibility(View.VISIBLE);
        }else if (i== View.INVISIBLE){
            mToolbar.setVisibility(View.INVISIBLE);
        }
        return this;
    }


}
